<?php
/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/10/12
 * Time: 10:13
 */

namespace App\admin\TableView;


use App\admin\TableView\BaseClass\BaseViewList;
use App\Jobs\Fun;
use App\Models\Admin\ApilistModel;
use App\Models\Admin\CategoryModel;
use App\Models\Admin\CompanyModel;
use App\Models\Admin\UserModel;
use App\Models\AreaModel;
use App\Models\Main\AdModel;
use Faker\Provider\Company;

class AdListView extends BaseViewList
{

    public function get_model()
    {

        return new AdModel();
    }

    public $show_add = true; ///显示添加按钮
    /**
     * 是否显示删除按钮
     */
    public $show_delete = false;
    public $topTitle = '广告设置';
    public $PageSize = 10;

    public $breadcrumb = '<li><a href="/mcadmin">Home</a></li>
        <li><a href="javascript:;">广告设置</a></li>
        ';

    public $html = '';


    //  public $show_add = false; ///显示添加按钮

    /**
     * 获取表格的唯一名字
     */
    public function getName()
    {
        return 'AdModel';
    }


    /**
     * 需要继承,然后定义每行需要显示的数据格式
     */
    public function Labels()
    {
        return array(
            //   BaseViewList::Button_checkbox=>[],
            'id' => 10,
            'paixu' => 40,
            'genre' => 50,
            'img' => 150,
            'link' => 150,
            BaseViewList::Button_control => [

                BaseViewList::Button_Edit,
                BaseViewList::Button_Delete

            ]
        );
    }

    /**
     * 对话框中的各个字段
     */
    public function dialog()
    {
        return array(

            array(
                'zd' => 'genre',
                'type' => self::dialog_list,
                'data' => AdModel::getGenre()
            ),
            array(
                'zd' => 'img',
                'type' => self::dialog_Img
            ),
            array(
                'zd' => 'link',
                'type' => self::dialog_text
            ),
            array(
                'zd' => 'paixu',
                'type' => self::dialog_number
            ),
        );
    }

    /**
     * 方便继承,多一层过滤
     */
    public function ModelTohtml($key, $model)
    {
        if($key==='genre'){
            return AdModel::getGenre($model->$key);
        }

        return parent::ModelTohtml($key, $model);
    }

    /**
     * 返回查询的条件
     */
    public function find()
    {
        $find = $this->get_model()->where([
        ]);
        $genre=$_GET['genre']??'all';
        if($genre!=='all'){
            $find->where([
                'genre'=>$genre
            ]);
        }

        $find->orderBy('paixu', 'DESC');
        return $find;
    }


    /**
     * 顶部的选择区,参数,如果为空,则不显示选择器
     */
    public function getselectAttr()
    {

        ///例子
        $where = [
            'genre' =>
                [
                    'title' => '广告位',
                    'inputtype' => self::dropDownList,
                    'items' => ['all' => '所有']+AdModel::getGenre() ,
                    'default' => 'all'
                ]
        ];
        return $where;
    }

}
